home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / thepit.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  7KB  |  329 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. extern unsigned char *galaxian_attributesram;
  13.  
  14. static int graphics_bank = 0;
  15. static int sound_enabled = 0;
  16.  
  17. static struct rectangle spritevisiblearea =
  18. {
  19.     2*8+1, 32*8-1,
  20.     2*8, 30*8-1
  21. };
  22. static struct rectangle spritevisibleareaflipx =
  23. {
  24.     0*8, 30*8-2,
  25.     2*8, 30*8-1
  26. };
  27.  
  28.  
  29. /***************************************************************************
  30.  
  31.   Convert the color PROMs into a more useable format.
  32.  
  33.   bit 7 -- 220 ohm resistor  -- BLUE
  34.         -- 470 ohm resistor  -- BLUE
  35.         -- 220 ohm resistor  -- GREEN
  36.         -- 470 ohm resistor  -- GREEN
  37.         -- 1  kohm resistor  -- GREEN
  38.         -- 220 ohm resistor  -- RED
  39.         -- 470 ohm resistor  -- RED
  40.   bit 0 -- 1  kohm resistor  -- RED
  41.  
  42.  
  43. ***************************************************************************/
  44. void thepit_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  45. {
  46.     int i;
  47.  
  48.  
  49.  
  50.     /* first of all, allocate primary colors for the background and foreground */
  51.     /* this is wrong, but I don't know where to pick the colors from */
  52.     for (i = 0;i < 8;i++)
  53.     {
  54.         *(palette++) = 0xff * ((i >> 2) & 1);
  55.         *(palette++) = 0xff * ((i >> 1) & 1);
  56.         *(palette++) = 0xff * ((i >> 0) & 1);
  57.     }
  58.  
  59.     for (i = 0;i < Machine->drv->total_colors-8;i++)
  60.     {
  61.         int bit0,bit1,bit2;
  62.  
  63.  
  64.         bit0 = (color_prom[i] >> 0) & 0x01;
  65.         bit1 = (color_prom[i] >> 1) & 0x01;
  66.         bit2 = (color_prom[i] >> 2) & 0x01;
  67.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  68.         bit0 = (color_prom[i] >> 3) & 0x01;
  69.         bit1 = (color_prom[i] >> 4) & 0x01;
  70.         bit2 = (color_prom[i] >> 5) & 0x01;
  71.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  72.         bit0 = 0;
  73.         bit1 = (color_prom[i] >> 6) & 0x01;
  74.         bit2 = (color_prom[i] >> 7) & 0x01;
  75.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  76.     }
  77.  
  78.     for (i = 0;i < Machine->drv->total_colors-8;i++)
  79.     {
  80.         colortable[i] = i + 8;
  81.     }
  82. }
  83.  
  84.  
  85. WRITE_HANDLER( intrepid_graphics_bank_select_w )
  86. {
  87.     if (graphics_bank != (data << 1))
  88.     {
  89.         graphics_bank = data << 1;
  90.         memset(dirtybuffer,1,videoram_size);
  91.     }
  92. }
  93.  
  94.  
  95. WRITE_HANDLER( thepit_flipx_w )
  96. {
  97.     if (*flip_screen_x != (data & 1))
  98.     {
  99.         *flip_screen_x = data & 1;
  100.         memset(dirtybuffer,1,videoram_size);
  101.     }
  102. }
  103.  
  104. WRITE_HANDLER( thepit_flipy_w )
  105. {
  106.     if (*flip_screen_y != (data & 1))
  107.     {
  108.         *flip_screen_y = data & 1;
  109.         memset(dirtybuffer,1,videoram_size);
  110.     }
  111. }
  112.  
  113.  
  114. READ_HANDLER( thepit_input_port_0_r )
  115. {
  116.     /* Read either the real or the fake input ports depending on the
  117.        horizontal flip switch. (This is how the real PCB does it) */
  118.     if (*flip_screen_x)
  119.     {
  120.         return input_port_3_r(offset);
  121.     }
  122.     else
  123.     {
  124.         return input_port_0_r(offset);
  125.     }
  126. }
  127.  
  128.  
  129. WRITE_HANDLER( thepit_sound_enable_w )
  130. {
  131.     if (sound_enabled && !data)
  132.     {
  133.         AY8910_reset(0);
  134.     }
  135.  
  136.     sound_enabled = data;
  137. }
  138.  
  139. static void common_AY8910_w(int offset, int data,
  140.                             mem_write_handler write_port,
  141.                             mem_write_handler control_port)
  142. {
  143.     /* Get out if sound is off */
  144.     if (!sound_enabled) return;
  145.  
  146.     if (offset & 1)
  147.     {
  148.         write_port(0, data);
  149.     }
  150.     else
  151.     {
  152.         control_port(0, data);
  153.     }
  154. }
  155.  
  156. WRITE_HANDLER( thepit_AY8910_0_w )
  157. {
  158.     common_AY8910_w(offset, data, AY8910_write_port_0_w, AY8910_control_port_0_w);
  159. }
  160.  
  161. WRITE_HANDLER( thepit_AY8910_1_w )
  162. {
  163.     common_AY8910_w(offset, data, AY8910_write_port_1_w, AY8910_control_port_1_w);
  164. }
  165.  
  166. /***************************************************************************
  167.  
  168.   Draw the game screen in the given osd_bitmap.
  169.   Do NOT call osd_update_display() from this function, it will be called by
  170.   the main emulation engine.
  171.  
  172. ***************************************************************************/
  173. static void drawtiles(struct osd_bitmap *bitmap,int priority)
  174. {
  175.     int offs,spacechar=0;
  176.  
  177.  
  178.     if (priority == 1)
  179.     {
  180.         /* find the space character */
  181.         while (Machine->gfx[0]->pen_usage[spacechar] & ~1) spacechar++;
  182.     }
  183.  
  184.  
  185.     /* for every character in the Video RAM, check if it has been modified */
  186.     /* since last time and update it accordingly. */
  187.     for (offs = videoram_size - 1;offs >= 0;offs--)
  188.     {
  189.         int bgcolor;
  190.  
  191.  
  192.         bgcolor = (colorram[offs] & 0x70) >> 4;
  193.  
  194.         if ((priority == 0 && dirtybuffer[offs]) ||
  195.                 (priority == 1 && bgcolor != 0 && (colorram[offs] & 0x80) == 0))
  196.         {
  197.             int sx,sy,code,bank,color;
  198.  
  199.  
  200.             dirtybuffer[offs] = 0;
  201.  
  202.             sx = (offs % 32);
  203.             sy = 8*(offs / 32);
  204.  
  205.             if (priority == 0)
  206.             {
  207.                 code = videoram[offs];
  208.                 bank = graphics_bank;
  209.             }
  210.             else
  211.             {
  212.                 code = spacechar;
  213.                 bank = 0;
  214.  
  215.                 sy = (sy - galaxian_attributesram[2 * sx]) & 0xff;
  216.             }
  217.  
  218.             if (*flip_screen_x) sx = 31 - sx;
  219.             if (*flip_screen_y) sy = 248 - sy;
  220.  
  221.             color = colorram[offs] & 0x07;
  222.  
  223.             /* set up the background color */
  224.             Machine->gfx[bank]->
  225.                     colortable[color * Machine->gfx[graphics_bank]->color_granularity] =
  226.                     Machine->pens[bgcolor];
  227.  
  228.             drawgfx(priority == 0 ? tmpbitmap : bitmap,Machine->gfx[bank],
  229.                     code,
  230.                     color,
  231.                     *flip_screen_x,*flip_screen_y,
  232.                     8*sx,sy,
  233.                     0,TRANSPARENCY_NONE,0);
  234.         }
  235.     }
  236.  
  237.  
  238.     /* copy the temporary bitmap to the screen */
  239.     if (priority == 0)
  240.     {
  241.         int i, scroll[32];
  242.  
  243.         if (*flip_screen_x)
  244.         {
  245.             for (i = 0;i < 32;i++)
  246.             {
  247.                 scroll[31-i] = -galaxian_attributesram[2 * i];
  248.                 if (*flip_screen_y) scroll[31-i] = -scroll[31-i];
  249.             }
  250.         }
  251.         else
  252.         {
  253.             for (i = 0;i < 32;i++)
  254.             {
  255.                 scroll[i] = -galaxian_attributesram[2 * i];
  256.                 if (*flip_screen_y) scroll[i] = -scroll[i];
  257.             }
  258.         }
  259.  
  260.         copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  261.     }
  262. }
  263.  
  264. static void drawsprites(struct osd_bitmap *bitmap,int priority)
  265. {
  266.     int offs;
  267.  
  268.  
  269.     /* draw low priority sprites */
  270.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  271.     {
  272.         if (((spriteram[offs + 2] & 0x08) >> 3) == priority)
  273.         {
  274.             int sx,sy,flipx,flipy;
  275.  
  276.  
  277.             if (spriteram[offs + 0] == 0 ||
  278.                 spriteram[offs + 3] == 0)
  279.             {
  280.                 continue;
  281.             }
  282.  
  283.             sx = (spriteram[offs+3] + 1) & 0xff;
  284.             sy = 240 - spriteram[offs];
  285.  
  286.             flipx = spriteram[offs + 1] & 0x40;
  287.             flipy = spriteram[offs + 1] & 0x80;
  288.  
  289.             if (*flip_screen_x)
  290.             {
  291.                 sx = 242 - sx;
  292.                 flipx = !flipx;
  293.             }
  294.  
  295.             if (*flip_screen_y)
  296.             {
  297.                 sy = 240 - sy;
  298.                 flipy = !flipy;
  299.             }
  300.  
  301.             /* Sprites 0-3 are drawn one pixel to the left */
  302.             if (offs <= 3*4) sy++;
  303.  
  304.             drawgfx(bitmap,Machine->gfx[graphics_bank | 1],
  305.                     spriteram[offs + 1] & 0x3f,
  306.                     spriteram[offs + 2] & 0x07,
  307.                     flipx,flipy,
  308.                     sx,sy,
  309.                     *flip_screen_x & 1 ? &spritevisibleareaflipx : &spritevisiblearea,TRANSPARENCY_PEN,0);
  310.         }
  311.     }
  312. }
  313.  
  314.  
  315. void thepit_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  316. {
  317.     /* low priority tiles */
  318.     drawtiles(bitmap,0);
  319.  
  320.     /* low priority sprites */
  321.     drawsprites(bitmap,0);
  322.  
  323.     /* high priority tiles */
  324.     drawtiles(bitmap,1);
  325.  
  326.     /* high priority sprites */
  327.     drawsprites(bitmap,1);
  328. }
  329.